package com.yin.myproject.thread.syncdemo;

/**
 * 修饰代码块
 *
 * @author Eason
 * @create 2018-05-09 15:49
 **/
public class SynchronizedDemo02 implements Runnable {

    private static Counter counter = new Counter();

    public static void main(String[] args) {
        SynchronizedDemo02 demo = new SynchronizedDemo02();
        Thread thread1 = new Thread(new SynchronizedDemo02(), "SyncThread1");
        Thread thread2 = new Thread(new SynchronizedDemo02(), "SyncThread2");
        Thread thread3  = new Thread(() -> counter.decrease(),"SyncThread3");
        thread1.start();
        thread2.start();
        thread3.start();
    }

    @Override
    public void run() {
        counter.increase();
    }

    public int getCount() {
        return counter.getCount();
    }

}
